/**
 * 主路由组件
 */
import React, { Component } from 'react'
import { Redirect, Switch, Route } from 'react-router-dom'
import { Layout } from 'antd';
import {connect} from 'react-redux'

import MyHeader from '../../components/header'
import MySider from '../../components/sider'
import NotFound from '../../components/error/404'

import Home from '../home/home'
import User from '../user/user'
import Role from '../role/role'
import Product from '../product/product'
import Category from '../category/category'
import Shop from '../shop/shop'
import AddProduct from '../addProduct/addProduct'
import Order from '../order/order'
import Finance from '../finance/finance'
import Swiper from '../swiper/swiper'

const { Content, Footer } = Layout;

class Admin extends Component{
  render() {
    const user = this.props.user
    if(!user.id){
      return <Redirect to="/login" />
    }
    return(
      <Layout style={{ height: '100vh' }}>
        <MySider style={{ overflow: 'auto', height: '100vh', position: 'fixed', left: 0 }}></MySider>
        <Layout style={{marginLeft:'200px'}}>
          <MyHeader></MyHeader>
          <Content style={{margin: '20px 20px 0', minHeight: 'auto'}}>
            <Switch>
              <Route exact path="/" component={Home} />
              <Route path="/home" component={Home} />
              <Route path="/sys/user" component={User} />
              <Route path="/sys/role" component={Role} />
              <Route path="/products/product" component={Product} />
              <Route path="/products/addProduct" component={AddProduct} />
              <Route path="/shops/category" component={Category} />
              <Route path="/shops/shop" component={Shop} />
              <Route path="/order" component={Order} />
              <Route path="/finance" component={Finance} />
              <Route path="/swiper" component={Swiper} />
              <Route component={NotFound} />
            </Switch>
          </Content>
          <Footer style={{ textAlign: 'center' }}>Ant Design ©2018 Created by Ant UED</Footer>
        </Layout>
      </Layout>
    )
  }
}
export default connect(
  state => ({
    user: state.user
  })
)(Admin)